package com.me.vo;

import java.io.Serializable;
import java.util.Collections;

/**
 * 分页对象
 * @author dong
 */
public class Page implements Serializable {
	private static final long serialVersionUID = 1L;

	// 该页的数据
	private Object data;
	
	// 该页的页码
	private Integer page;
	
	// 每页显示几条
	private Integer rows;
	
	// 总记录数
	private Integer totalCount;
	
	// 总页数
	private Integer totalPage;

	/**
	 * 构造一个空页码
	 */
	public Page() {
		this(Collections.EMPTY_LIST, 0);
	}

	/**
	 * 传入数据和总记录数，默认显示第一页，前10条记录
	 * @param data
	 * @param totalCount
	 */
	public Page(Object data, Integer totalCount) {
		this.data = data;
		this.page = 1;
		this.rows = 10;
		this.totalCount = totalCount;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	public Integer getPage() {
		return page;
	}

	public void setPage(Integer page) {
		this.page = page;
	}

	public Integer getRows() {
		return rows;
	}

	public void setRows(Integer rows) {
		this.rows = rows;
	}

	public Integer getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Integer totalCount) {
		this.totalCount = totalCount;
	}

	/**
	 * 计算总页数
	 * @return
	 */
	public Integer getTotalPage() {
		if(totalCount == 0){
			totalPage = 0;
		} else{
			totalPage = totalCount/rows;
			totalPage = totalPage + ((totalCount % rows > 0) ? 1 : 0);
		}
		return totalPage;
	}

	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}

	@Override
	public String toString() {
		return "Page [data=" + data + ", page=" + page + ", rows=" + rows
				+ ", totalCount=" + totalCount + ", totalPage=" + totalPage
				+ "]";
	}
}
